package com.cheyun.netsalev3.view

import android.os.Bundle
import android.view.View
import com.cheyun.netsalev3.R
import com.cheyun.netsalev3.utils.BaseActivity
import com.cheyun.netsalev3.DmChatFragment
import com.cheyun.netsalev3.MyApplication
import com.cheyun.netsalev3.databinding.ActivityTimChatBinding
import com.cheyun.netsalev3.floatpermission.FloatPermissionManager
import com.cheyun.netsalev3.widget.floatingview.FloatingView

class TimChatActivity : BaseActivity<ActivityTimChatBinding>() {
    override fun initContentView(): Int {
        return R.layout.activity_tim_chat
    }

    override fun initView() {
//        FloatActionController.getInstance().hide()
//        FloatingView.get().remove()
        FloatingView.get().view.visibility = View.GONE
        MyApplication.getInstance().enableShowMsg = false
    }

    override fun initData() {
        showFloatView()
    }

    //悬浮窗权限开启
    private fun showFloatView(){
        //开启悬浮窗
        val isPermission = FloatPermissionManager.getInstance().applyFloatWindow(this,windowManager.defaultDisplay.width)
//        //有对应权限或者系统版本小于7.0
//        if (isPermission || Build.VERSION.SDK_INT < 24) {
//            FloatActionController.getInstance().startMonkServer(this)
//        }
//        handler.postDelayed(runnable, 1500);
    }
    override fun onDestroy() {
        super.onDestroy()
//        FloatActionController.getInstance().show()
//        FloatingView.get().add();
        FloatingView.get().show()
        MyApplication.getInstance().enableShowMsg = true
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (savedInstanceState == null) {
            supportFragmentManager.beginTransaction()
                    .replace(R.id.container, DmChatFragment.newInstance())
                    .commitNow()
        }
    }

}
